import {ref, computed} from 'vue';
import {defineStore} from 'pinia';

const config = {
  // 持久化存储
  persist: {
    // 设置key名 默认持久所有的数据
    key: 'locale',
    // 修改存储位置 默认在localStorage中
    // storage: sessionStorage,
    // 只想持久化单个数据
    // paths: ['count', 'xxxx'], // 要持久化的属性
  },
};

export const useLocaleStore = defineStore(
  'locale',
  () => {
    const localInfo = ref<any>({});
    const getLocale = computed(() => {
      return localInfo.value?.locale ?? 'zh_CN'; // 默认中文
    });
    const setLocaleInfo = (info: any) => {
      console.log('setLocaleInfo', info);
      localInfo.value = {...localInfo.value, ...info};
    };
    return {localInfo, getLocale, setLocaleInfo};
  },
  config,
);
